#pragma once
#include "delegate.h"
/** \brief Provide event handler prototype.
 */


template<typename ... ParasPack>
class EventHandle
{
protected:
	delegate_m(bool, Event, ParasPack ...);
	std::list<Event*> lp;
public:
	virtual void ProcDrv(ParasPack ... args)
	{
		for (auto it = this->lp.rbegin(); it != this->lp.rend(); it++)
		{
			if ((*(*it))(args ...) == false) break;
		}
	}
	EventHandle& operator += (Event proc)
	{
		this->lp.push_back(new Event(proc));
		return *this;
	}
};

template<>
class EventHandle<void>
{
protected:
	delegate_m(bool, Event, void);
	std::list<Event*> lp;
public:
	virtual void ProcDrv(void)
	{
		for (auto it = this->lp.rbegin(); it != this->lp.rend(); it++)
		{
			if ((*(*it))() == false) break;
		}
	}
	EventHandle& operator += (Event proc)
	{
		this->lp.push_back(new Event(proc));
		return *this;
	}
};
